class ReceivingTicketsController < ApplicationController
  # GET /receiving_tickets
  # GET /receiving_tickets.json
  def index
    @receiving_tickets = ReceivingTicket.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json=> @receiving_tickets }
    end
  end

  # GET /receiving_tickets/1
  # GET /receiving_tickets/1.json
  def show
    @receiving_ticket = ReceivingTicket.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render :json=> @receiving_ticket }
    end
  end

  # GET /receiving_tickets/new
  # GET /receiving_tickets/new.json
  def new
    @receiving_ticket = ReceivingTicket.new
    @receiving_ticket.build_rt_proveedor
    @receiving_ticket.build_rt_transportista
    @receiving_ticket.build_rt_mercancia
    @receiving_ticket.build_reexpedicion
    @tipos_entrada = TipoEntrada.all
    @destinos = Pais.all
    @clientes = Cliente.all
    @proveedores = Proveedor.all
    @transportistas = Transportista.all
    @empleados = Empleado.all
    @unidades_medida = UnidadMedida.all
    @estatus_mercancias = EstatusMercancia.all
    @incidencias = Incidencia.all
    @cliente= Cliente.find(params[:IdCliente])
    @vias = Transportista.all
    @tipos_envio = TipoEnvio.all
    

    respond_to do |format|
      format.html # new.html.erb
      format.json { render :json=> @receiving_ticket }
    end
  end

  # GET /receiving_tickets/1/edit
  def edit
    @receiving_ticket = ReceivingTicket.find(params[:id])
  end

  # POST /receiving_tickets
  # POST /receiving_tickets.json
  def create
    @receiving_ticket = ReceivingTicket.new(params[:receiving_ticket])

    respond_to do |format|
      if @receiving_ticket.save
        format.html { redirect_to receiving_tickets_path, :notice=> 'Receiving ticket was successfully created.' }
        format.json { render :json=> @receiving_ticket, :status=> :created, :location=> @receiving_ticket }
      else
        format.html { render :action=> "new" }
        format.json { render :json=> @receiving_ticket.errors, :status=> :unprocessable_entity }
      end
    end
  end

  # PUT /receiving_tickets/1
  # PUT /receiving_tickets/1.json
  def update
    @receiving_ticket = ReceivingTicket.find(params[:id])

    respond_to do |format|
      if @receiving_ticket.update_attributes(params[:receiving_ticket])
        format.html { redirect_to receiving_tickets_path, :notice=> 'Receiving ticket was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render :action=> "edit" }
        format.json { render :json=> @receiving_ticket.errors, :status=> :unprocessable_entity }
      end
    end
  end
  
  def seleccionar_cliente
    puts params
    @accion = params[:accion]
    @clientes = Cliente.all
  end
  
  def cliente_rt
    redirect_to :action=> params[:accion] , :IdCliente => params[:cliente_rt][:IdCliente]
  end
  
  def agregar_proveedor
    @proveedor = Proveedor.new
    @giros = GiroEmpresa.all
  end

  # DELETE /receiving_tickets/1
  # DELETE /receiving_tickets/1.json
  def destroy
    @receiving_ticket = ReceivingTicket.find(params[:id])
    @receiving_ticket.destroy

    respond_to do |format|
      format.html { redirect_to receiving_tickets_url }
      format.json { head :no_content }
    end
  end
end
